﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Happy.ExtentionMethods;
using Happy.Domain;

namespace Happy.Examples.OrderManagement.Domain.Orders
{
    public sealed class OrderItem : Entity<Guid>
    {
        public OrderItem(
            Guid productId,
            string product,
            decimal price,
            int quantity)
        {
            product.MustNotNullAndNotWhiteSpace("product");
            price.MustGreaterThan("price", 0);
            quantity.MustGreaterThan("quantity", 0);

            this.Id = productId;
            this.Product = product;
            this.Price = price;

            this.ChangeQuantity(quantity);
        }

        public Guid ProductId { get { return this.Id; } }

        public string Product { get; private set; }

        public decimal Price { get; private set; }

        public int Quantity { get; private set; }

        public decimal Subtotal { get; private set; }

        public Guid OrderId { get; internal set; }

        internal void ChangeQuantity(int quantity)
        {
            this.Quantity = quantity;

            this.Subtotal = this.Price * this.Quantity;
        }
    }
}
